package xiangMu.auto.auto02;

import java.util.Scanner;

public class RentalOperate {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        RentalCarsCompany rentalCompany = new RentalCarsCompany("金路至尊租赁有限公司", "合肥市瑶海区明光路160号", "999999999");
        int choice;
        System.out.println(rentalCompany);
        while (true) {
            System.out.println("本公司现有" + rentalCompany.getsumAuto() + "辆车可租");
            System.out.println("1:查看车辆情况，2:租赁，3:还车，4:报废，5:采购新车，6:查看租赁记录，9:退出");
            System.out.print("请选择:");
            choice = input.nextInt();
            if (choice == 1) {
                System.out.println("--查看车辆情况--");
                System.out.print("请输入要查看的车辆类型(轿车/客车):");
                String type;
                while (!(type = input.next()).equals("轿车") && !type.equals("客车"))
                    System.out.print("类型选择错误，请重新输入:");
                rentalCompany.showTypeAll(type);    //显示该类型的全部车辆(不考虑状态)
            } else if (choice == 2) {
                System.out.println("--租赁--");
                System.out.print("请输入要租赁的车辆类型(轿车/客车):");
                String type;
                while (!(type = input.next()).equals("轿车") && !type.equals("客车"))
                    System.out.print("类型选择错误，请重新输入:");
                System.out.println("现有车辆如下:");
                rentalCompany.showType(type);   //显示未出租状态的该类型车辆
                System.out.print("请选择要租赁的车辆，请输入车牌号:");
                String licencePlate = input.next();
                Auto auto = rentalCompany.find(licencePlate);
                if (auto == null) {
                    System.out.println("租赁失败，无此车型可租");  //未找到有该车牌号的车辆
                    continue;   //结束本次while循环，下面的语句不会再执行，开始下一次循环
                } else {
                    System.out.println("您租赁的车型是" + auto.getBrand() + auto.getSeries() + ",车牌号为:" + auto.getLicencePlate() + "," + auto.getSeatNumber() + "座");
                }
                System.out.print("请输入租赁的天数:");
                int days;
                while ((days = input.nextInt()) <= 0)
                    System.out.print("租赁天数输入错误，请重新输入:");
                auto = rentalCompany.rentAuto(licencePlate, type, days);
                if (auto == null) {
                    System.out.println("租赁失败，无此车型可租");  //车辆已出租或车牌号对应的车辆类型错误
                } else {
                    System.out.println("请支付" + auto.calcRent(days) + "元");
                    System.out.println("用车愉快!");
                }
            } else if (choice == 3) {
                System.out.println("--还车--");
                System.out.print("请输入车牌号:");
                String licencePlate = input.next();
                if (rentalCompany.returnAuto(licencePlate))
                    System.out.println("还车成功,下次继续合作");
                else
                    System.out.println("归还失败，请核对信息");
            } else if (choice == 4) {
                System.out.println("--报废--");
                System.out.print("请输入车辆类型(轿车/客车):");
                String type;
                while (!(type = input.next()).equals("轿车") && !type.equals("客车"))
                    System.out.print("类型选择错误，请重新输入:");
                System.out.print("请输入车牌号:");
                String licencePlate = input.next();
                if (rentalCompany.delAuto(licencePlate, type))
                    System.out.println(type + licencePlate + "报废成功");
                else
                    System.out.println("报废失败");
            } else if (choice == 5) {
                System.out.println("--采购新车--");
                System.out.print("请输入新车的类型(轿车/客车):");
                String type;
                while (!(type = input.next()).equals("轿车") && !type.equals("客车"))
                    System.out.print("类型选择错误，请重新输入:");
                Auto auto;  //抽象类不能实例化，但是可以作为上转型对象
                if (type.equals("轿车")) {
                    auto = new Car();
                    auto.setType("轿车");
                } else {
                    auto = new Bus();
                    auto.setType("客车");
                }
                System.out.print("请输入新车的品牌:");
                auto.setBrand(input.next());
                System.out.print("请输入新车的型号:");
                auto.setSeries(input.next());
                System.out.print("请输入新车的车牌号:");
                auto.setLicencePlate(input.next());
                System.out.print("请输入新车的座位数:");
                auto.setSeatNumber(input.nextInt());
                System.out.print("请输入新车的日租金:");
                auto.setDayRent(input.nextInt());
                rentalCompany.addAuto(auto);
            } else if (choice == 6) {
                System.out.println("--查看租赁记录--");
                rentalCompany.getAutoRecord();
            } else if (choice == 9) {
                System.out.println("--退出--");
                break;
            } else {
                System.out.println("输入错误，请重新输入");
                continue;
            }
        }
        System.out.println("欢迎下次光临");

    }
}
